package com.platform.base.utils;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

/**
 * @CLASS_NAME: JsonUtil
 * @Description TODO
 * @Date 2021/2/23 15:39
 * @Author lei.ren
 */
public class JsonUtil {
    public static String toJson(Object obj) {
        return JSON.toJSONString(obj);
    }

    public static Object fromJson(String str) {
        return JSON.parseObject(str);
    }

    public static <T> T fromJson(String str, Class<T> clsT) {
        return JSON.parseObject(str, clsT);
    }

    public static <T> List<T> fromJsonList(String str, Class<T> clsT) {
        return JSON.parseArray(str, clsT);
    }

    public static <T> T fromJson(String str, TypeReference<T> typeReference) {
        return JSON.parseObject(str, typeReference);
    }
}
